package com.ggg.clothesshop.service.IMPL;

import com.ggg.clothesshop.mapper.AddressMapper;
import com.ggg.clothesshop.model.Address;
import com.ggg.clothesshop.model.Product;
import com.ggg.clothesshop.service.AddressService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class AddressServiceIMPL implements AddressService {

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public int addAddress(Address address) {
        return addressMapper.insert(address);
    }

    @Override
    public PageInfo<Address> selectByPage(int pageNum, int pageSize, int userid) {
        PageHelper.startPage(pageNum, pageSize);
        ArrayList<Address> addresses = addressMapper.selectAddressesByUser(userid);
        PageInfo result = new PageInfo(addresses);
        return result;
    }

    @Override
    public int deleteAddress(int addressid) {
        return addressMapper.deleteByPrimaryKey(addressid);
    }

    @Override
    public List<Address> selectListAddress(int userid) {
        ArrayList<Address> listAddress = addressMapper.selectAddressesByUser(userid);
        return listAddress;
    }

    @Override
    public Address selectById(int addressid) {

        return addressMapper.selectByPrimaryKey(addressid);
    }

    @Override
    public int updateAddress(Address address) {
        return addressMapper.updateByPrimaryKeySelective(address);
    }
}
